/*
 * @lc app=leetcode.cn id=98 lang=javascript
 *
 * [98] 验证二叉搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isValidBST = function(root) {
    const check = function(node, low, high) {
        if (!node) return true  // 一定要到叶子节点都满足二叉搜索树的条件才能判断该子树为二叉搜索树
        if (node.val <= low || node.val >= high) return false
        return check(node.left, low, node.val) && check(node.right, node.val, high)
    }
    return check(root, -Infinity, Infinity)
};
// @lc code=end

